package com.qq.BFMRSE.requestModule;

import java.io.BufferedInputStream;
import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;

import com.qq.BFMRSE.entity.user;

public class registerModule {
	public static int registerNewUser(String url,user newUser){
		HttpClient httpClient=new HttpClient();
		PostMethod post=new PostMethod(url);
		post.addParameter("userName",newUser.getUserName());
		post.addParameter("email",newUser.getEmail());
		post.addParameter("pwd", newUser.getPwd());
		int stateCode=-1;
		boolean flag=false;
		try {
			stateCode=httpClient.executeMethod(post);
			String res=new String(post.getResponseBody());
			flag=Boolean.parseBoolean(res.trim());
			if(stateCode==200){
				if(!flag)
					return 1;//表示注册成功
				else 
					return 0;//表示用户名重复
			}else {
				return -1;//表示网络访问失败
				
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
		
	}

}
